/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package scrabble;

import java.util.ArrayList;
import javax.swing.Icon;
import javax.swing.ImageIcon;

/**
 *
 * @author KhoufiAsma
 */
public abstract class Sachet {
    ArrayList<Lettre> tabLettres=new ArrayList<>();
  

    abstract void remplirSachet();
  
    private int auHazardEntre(int a,int b)
    {
      double t=Math.random();
      return ((int)((b-a)*t+a));
    }
    private void melanger()
    {
        int alea;
        Lettre l;
        for(int i=0;i<tabLettres.size();i++)
        {
          alea=auHazardEntre(0,tabLettres.size())  ;
          l=tabLettres.get(i);
          tabLettres.set(i, tabLettres.get(alea));
          tabLettres.set(alea, l);
        }
        
    }
    


   
    public Lettre tirerlettre()
    {
    int alea;
    Lettre l;
    Icon icon =new ImageIcon("../case mot double.JPG");
    
    do
    {
    alea=auHazardEntre(0,tabLettres.size());
    l=tabLettres.get(alea);
    l.setIcon(icon);

    
    }
    while(l.getOccurence()==0);
 
      int j=l.getOccurence();
       
       
      j--;
    l.setOccurence(j);
     
  
    return l;
       
    }
    
    
    
    public Lettre changerLettre(Lettre l)
    {
    	Lettre l1=tirerlettre();
        int occ;
        
        occ=l.getOccurence();
        
        l.setOccurence(++occ);
       
        
     return l1; 
    }
    
    public int nb_lettres_restantes()
    {
        
        int s=0;
         
        for(int i=0;i<tabLettres.size();i++)
        { 
        s+=tabLettres.get(i).getOccurence();
        }
        
         return s;
    }
    
}   